package refercese;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Random;
import java.util.function.Function;
import java.util.function.Predicate;

import org.junit.Test;

// ref        引用缩写
// refer      引用
// reference  引用
public class StaticReferenceDemo {
    
	private static String nextEnglish(int length) {
		StringBuilder sb = new StringBuilder("");
		for (int i = 0 ; i < length ; i++) {
			if (new Random().nextBoolean()) {
				//大写 'A' ~ 'Z'
				sb.append((char)(new Random().nextInt(26) + 65));
			}else {
				//小写 'a' ~ 'z'
				sb.append((char)(new Random().nextInt(26) + 97));
			}
		}
		return sb.toString();
	}
	
	@Test
	public void test1() {
		//  boolean test(T t);  = boolean isNull(Object obj)  用人家现成的方法体给抽象方法赋值
		Predicate<String> p = Objects::isNull;
		System.out.println(p.test(null));   // true  Objects.isNull(null)
		System.out.println(p.test("abc"));  // false Objects.isNull("abc")
		
		//  R apply(T t) = double abs(double )
		Function<Double,Double> f = Math::abs;
		System.out.println(f.apply(-5.0));  // Math::abs(-5)
		
		// 
		Function<Integer,String> f2 = StaticReferenceDemo::nextEnglish;
		System.out.println(f2.apply(10));   // StaticReferenceDemo.nextEnglish(10)
	}
}
